<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<input type="file" id="file">
<button id="uploadImg">test</button>

<img src="" alt="" id="img">

<script>
    $("#uploadImg").on("click", function () {
        var type = "file";          //后台接收时需要的参数名称，自定义即可
        var id = "file";            //即input的id，用来寻找值
        var formData = new FormData();
        formData.append(type, $("#" + id)[0].files[0]);    //生成一对表单属性
        $.ajax({
            type: "POST",           //因为是传输文件，所以必须是post
            url: 'http://192.168.0.142:8040/upload/fileUpload',         //对应的后台处理类的地址
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                console.log(data);
                $("#img").attr('src','http://192.168.0.142:8040/'+data);
            }
        })
    });
</script>
</body>
</html>